Skip to content

feat: 支持 CodeCC 前端子路径部署#95

Open
brookylin wants to merge 3 commits into
TencentBlueKing:masterfrom
brookylin:master
Open

feat: 支持 CodeCC 前端子路径部署#95
brookylin wants to merge 3 commits into
TencentBlueKing:masterfrom
brookylin:master

Conversation

@brookylin

@brookylin brookylin commented May 13, 2026

Copy link
Copy Markdown
Collaborator

本次改造让 CodeCC 前端支持部署在 / 或任意配置的子路径下,并保持现有根路径访问兼容。

主要内容:

  • 新增 BK_SITE_PATH、BK_STATIC_URL 运行时配置,并统一路由 base、静态资源 public path、登录回调、cookie path 与内部链接处理。

  • 新增路径工具方法,修正 CodeCC 内部硬编码根路径跳转,支持绝对地址、协议相对地址和子路径拼接。

  • 调整本地 dev server 配置,使 npm run dev 在 BK_SITE_PATH 子路径下也能正确加载入口、异步 chunk 和 history fallback。

  • 部署配置、网关环境变量、Helm 模板和 nginx 前端模板补充 BK_SITE_PATH,支持网关按配置子路径回源到前端资源。

  • 新增 build 产物校验脚本、路径工具校验脚本和本地 subpath 静态服务脚本,便于验证根路径与子路径两种模式。

验证:

  • node ./scripts/verify-path-utils.js

  • node -c ./scripts/verify-subpath-dist.js

  • node -c ./scripts/serve-subpath-dist.js

  • node -c ./bk.config.js

brookylin added 3 commits May 13, 2026 11:23
本次改造让 CodeCC 前端支持部署在 / 或任意配置的子路径下,并保持现有根路径访问兼容。

主要内容:

- 新增 BK_SITE_PATH、BK_STATIC_URL 运行时配置,并统一路由 base、静态资源 public path、登录回调、cookie path 与内部链接处理。

- 新增路径工具方法,修正 CodeCC 内部硬编码根路径跳转,支持绝对地址、协议相对地址和子路径拼接。

- 调整本地 dev server 配置,使 npm run dev 在 BK_SITE_PATH 子路径下也能正确加载入口、异步 chunk 和 history fallback。

- 部署配置、网关环境变量、Helm 模板和 nginx 前端模板补充 BK_SITE_PATH,支持网关按配置子路径回源到前端资源。

- 新增 build 产物校验脚本、路径工具校验脚本和本地 subpath 静态服务脚本,便于验证根路径与子路径两种模式。

验证:

- node ./scripts/verify-path-utils.js

- node -c ./scripts/verify-subpath-dist.js

- node -c ./scripts/serve-subpath-dist.js

- node -c ./bk.config.js
# Reviewed, transaction id: 80134
@victorljii

Copy link
Copy Markdown
Collaborator

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

URL path duplication bug

In shareDefect(), paths passed to withSitePath() already contain the /codecc/ prefix. For example, withSitePath('/codecc/${projectId}/task/${taskId}/defect/lint/${toolName}/list') prepends BK_SITE_PATH (e.g., /codecc-demo/), producing /codecc-demo/codecc/... with a duplicate /codecc/ segment. The same pattern appears in isProjectDefect and isPaas branches. The fix is to strip /codecc/ from paths before calling withSitePath, or use the raw path without the prefix.

      let url = `${location.host}${withSitePath(`/codecc/${projectId}/task/${taskId}/defect/lint/${toolName}/list`)}
?entityId=${entityId}&status=${status}`;
      if (window.self !== window.top) {
        url = `${window.DEVOPS_SITE_URL}/console/codecc/${projectId}/task/${taskId}/defect/lint/${toolName}/list
?entityId=${entityId}&status=${status}`;
      }
      if (this.isProjectDefect) {
        url = `${location.host}${withSitePath(`/codecc/${projectId}/defect/list`)}
?entityId=${entityId}&status=${status}`;
        if (window.self !== window.top) {
          url = `${window.DEVOPS_SITE_URL}/console/codecc/${projectId}/defect/list
?entityId=${entityId}&status=${status}`;
        }
      }
      if (this.isPaas) {
        url = `${location.host}${withSitePath(`/paas/ignored/${toolName}/list`)}?entityId=${entityId}`;
URL path duplication bug

goToTaskDetailUrl() passes /codecc/${this.projectId}/task/${taskId}/detail to withSitePath(), which prepends BK_SITE_PATH. This results in /codecc-demo/codecc/... with a double /codecc/ when the site path is set. The path should not include /codecc/ before being passed to withSitePath, since the prefix is already added by the helper.

let path = withSitePath(`/codecc/${this.projectId}/task/${taskId}/detail`);
if (window.self !== window.top) {
  prefix = `${window.DEVOPS_SITE_URL}/console`;
  path = `/codecc/${this.projectId}/task/${taskId}/detail`;
}
return `${prefix}${path}`;
URL path duplication bug

In shareDefect(), the path /codecc/${projectId}/task/${taskId}/defect/compile/${toolName}/list is passed to withSitePath(), duplicating /codecc/ in the final URL when BK_SITE_PATH is set. The helper already prepends the site path, so the /codecc/ segment in the input path causes duplication.

let path = withSitePath(`/codecc/${projectId}/task/${taskId}/defect/compile/${toolName}/list`);
if (window.self !== window.top) {
  prefix = `${location.protocol}${window.DEVOPS_SITE_URL}/console`;
  path = `/codecc/${projectId}/task/${taskId}/defect/compile/${toolName}/list`;
}
const url = `${prefix}${path}
URL path duplication bug

openTaskOverview() constructs withSitePath('/codecc/${row.projectId}/task/${row.taskId}/detail'), which prepends BK_SITE_PATH to a path that already contains /codecc/. This results in /codecc-demo/codecc/... when deployed under a subpath.

const taskPath = withSitePath(`/codecc/${row.projectId}/task/${row.taskId}/detail`);
const url = `${window.location.origin}${taskPath}`;
window.open(url, '_blank');
URL path duplication bug

withStaticUrl('/static/login_success.html') prepends BK_STATIC_URL to a path that already starts with /static/. If BK_STATIC_URL equals BK_SITE_PATH (e.g., /codecc-demo/), the result becomes /codecc-demo/static/.... This is likely intentional for static assets under a subpath, but verify this is the desired behavior when BK_STATIC_URL is set to the site path rather than a separate CDN prefix.

const staticSuccessUrl = withStaticUrl('/static/login_success.html');
const successUrl = /^(https?:)?\/\//.test(staticSuccessUrl)
  ? staticSuccessUrl
  : `${window.location.origin}${staticSuccessUrl}`;
Lost 'group' property

The old 'task-settings' menu item had group: true which has been removed in the new code. This property was likely used for UI grouping/styling. The removal appears unintentional and could cause visual regression in the menu layout.

{
  id: 'task-settings',
  name: this.$t('设置'),
  routeName: 'task-settings',
  icon: 'codecc-icon icon-setting',
  ...resolveItem({
    name: 'task-settings-code',
    params: routeParams,
  }),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants